use std::time::SystemTime;
use chrono::{DateTime, Local};

#[derive(Debug, Clone)]
pub struct Message {
    pub topic: String,
    pub payload: String,
    pub formatted_timestamp: String,
}

impl Message {
    pub fn new(topic: String, payload: String) -> Self {
        let timestamp = SystemTime::now();
        Self {
            topic,
            payload,
            formatted_timestamp: format_system_time(timestamp),
        }
    }
}

fn format_system_time(timestamp: SystemTime) -> String {
    let datetime: DateTime<Local> = timestamp.into();
    datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}
